<template>
    <div>
        <c-header :p-title="'申请详情'">
            <div class="d-flex justify-content-end align-items-center">

                <button class="btn btn-sm btn-danger m-r-sm" @click='editVerityPass'>批量驳回</button>
                <button class="btn btn-sm btn-warning m-r-sm" @click='editVerity'>批量通过</button>
                <button type="button" class="btn btn-sm btn-info d-lg-block"  @click="$router.go(-1)"><i class="fa fa-mail-reply m-r-sm"></i>返回</button>
                <btn-refresh class='m-l-15' :p-data='init'></btn-refresh>
            </div>
        </c-header>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive"  v-if='list'>
                            <rich-table
                                    :p-data='list'
                                    :p-select="true"
                                    :p-plus-callback="richTablePlusCallback"
                                    :p-line-class="richTableLineClassCallback"
                                    @on-select="selectChange">
                                <div class="table-edit-group" slot="eidt" slot-scope="slotProps">
                                    <button v-if="slotProps.item.status=='-3'" class="btn btn-sm btn-success" type="button" @click="editStatus('ok',slotProps.item)">通过</button>
                                    <button v-if="slotProps.item.status=='-3'" class="btn btn-sm btn-danger m-l-sm" type="button" @click="editStatus('inject',slotProps.item)">驳回</button>
                                </div>
                            </rich-table>
                            <div  v-show='!list.length' class="text-center m-b-sm">
                                暂无数据！
                            </div>
                        </div>
                        <hr/>
                        <footer class="panel-footer text-right">
                            <CPage :total="search.page_total"
                                   :current='search.page_current'
                                   :page-size='search.page_row'
                                   @on-change='pageCurrentChange'
                                   @on-page-size-change='pageRowChange'></CPage>
                        </footer>
                    </div>
                </div>
            </div>
        </div>
        <operate-inject ref="operate_inject" @on-change="initSubmit"></operate-inject>
        <operate-ok ref="operate_ok" @on-change="initSubmit"></operate-ok>
        <operate-ok-more ref="operate_ok_more" @on-change="initSubmit"></operate-ok-more>
        <operate-no-more ref="operate_no_more" @on-change="initSubmit"></operate-no-more>
    </div>
</template>
<script>
    import serCustomer from '../../serves/api-customer'
    import operateInject from './OperateInject'
    import operateOk from './OperateOk'
    import richTable from './RichTable'
    import operateOkMore from './OperateOkMore.vue'
    import operateNoMore from './OperateNoMore.vue'

    const __page_key = 'customer.verity.detail';
    let searchDef = {
        page_row:'',
        page_current:'',
        page_total:''
    };
    export default{
        components:{
            richTable,
            operateInject,
            operateOk,
            operateOkMore,
            operateNoMore,
        },
        data(){
            return{
                id:'',
                list:undefined,
                search:{},
                selList:[]
            }
        },
        computed:{
        },
        beforeMount(){
            this.$set(this, 'id',this.pParams&&this.pParams.id||this.$route.params.id);
            this.searchReset();
        },
        mounted(){
            this.init();
        },
        methods:{
            searchReset(update,pageState){
                if(pageState){
                    this.$clientPage.def(this.search);
                    return false
                }
                const _p=this.$clientPage.getData(__page_key);
                if(_p){
                    this.$set(this,'search',_p);
                }else{
                    this.$set(this,'search',Object.assign({},searchDef));
                    this.$clientPage.def(this.search);
                }
                if(update){
                    this.init();
                }
            },
            searchPage(page){
                this.$clientPage.set(this.search,page);
            },
            searchChange(){
                this.$clientPage.def(this.search);
                this.init();
            },
            pageRowChange(num){
                if(num!= this.search.page_row){
                    this.$set(this.search,'page_row',num);
                    if(this.search.page_current == 1){
                        this.init();
                    }
                }
            },
            pageCurrentChange(current){
                if(current!= this.search.page_current){
                    this.$set(this.search,'page_current',current);
                    this.init();
                }
            },
            linkPageChange(name,params,query){
                this.$clientPage.setData(__page_key,Object.assign({},this.search));
                if(name){
                    this.$router.push({name:name,params:params,query:query})
                }
            },
            //------------------------------------------------------------------------
            async init(data){
                let res = await serCustomer.detailVerity({
                    page:this.search.page_current,
                    size:this.search.page_row,
                    id:this.id,
                });
                if(res.code==1){
                    res.data.forEach((v,i)=>{
                       if(v.status!='-3'){
                           v._disabled = true;
                       }
                    });
                    this.selList = [];
                    this.list = res.data||[];
                    this.searchPage(res.addtion_data&&res.addtion_data.page_info);
                }else{
                    this.list = [];
                    this.searchReset(undefined,true);
                    this.$Message.error(res.message);
                }
                return true;
            },
            richTablePlusCallback(){
                //重复数据 more_than_one
                return [{
                        title:'是否有重复数据',
                        width:155,
                        key:'more_than_one'
                    }]
            },
            richTableLineClassCallback(row,index){
                if(row.more_than_one>0){
                    return 'danger'
                }
            },
            initSubmit(state){
                if(state){
                    this.init()
                }
            },
            editStatus(type,data){
                let modal_name = '';
                if(type=='ok'){
                    modal_name = 'operate_ok'
                }else if(type=='inject'){
                    modal_name = 'operate_inject'
                }
                this.$refs[modal_name].handleOpen({
                    id:data.id
                });
            },
            selectChange(value){
                this.$set(this,'selList',value);
            },
            editVerity(){
                this.$refs['operate_ok_more'].handleOpen({
                    ids:this.selList
                })
            },
            editVerityPass(){
                this.$refs['operate_no_more'].handleOpen({
                    ids:this.selList
                })
            },
        }
    }
</script>